import { authCheck } from '@/utils/auth';
import { Notification } from 'element-ui';
import store from '@/store'

export default router => {
  router.beforeEach(async (to, from, next) => {
    if (to.meta && to.meta.module) {
      if (await authCheck()) {
        next();
      } else {
        Notification.error({
          title: '请先登录',
        });
        await store.dispatch('logout')
      }
    } else {
      next();
    }
  });
};